/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.beans.enterprise;

import ca.trader.except.LocationNotFoundException;
import ca.trader.except.SaleAlreadyFavouritedByUserException;
import ca.trader.except.SaleDoesNotExistException;
import ca.trader.except.SaleNotFavouritedByUserException;
import ca.trader.except.UserDoesNotExistException;
import ca.trader.except.UserNotAuthenticatedException;
import ca.trader.sale.Sale;
import ca.trader.sale.SaleLookupQuery;
import ca.trader.sale.SaleLookupResult;
import ca.trader.user.User;
import java.util.List;
import javax.ejb.Local;
import javax.servlet.http.HttpSession;

/**
 * The Business interface for the SaleBean to be used locally.
 *
 * @author Ahsan
 */
@Local
public interface SaleBeanLocal
{

	 /**
	  * *
	  * inserts a sale entity bean into the database.
	  *
	  * @param sale the sale entity bean to insert
	  */
	 void insertSale(Sale sale);

	 /**
	  * Gets a list of sales created by a seller within a given range
	  *
	  * @param seller the user that owns the sales
	  * @param offset the index (starting with 0) to start searching at
	  * @param limit the maximum result count to get
	  * @return the list of sales
	  */
	 List<Sale> getSalesBySeller(User seller, int offset, int limit);

	 /**
	  * Gets the sale created by the seller whose ID is provided
	  *
	  * @param sellerID the ID of the seller
	  * @param offset the index (starting with 0) to start searching at
	  * @param limit the maximum result count to get
	  * @return the list of sales.  returns an empty list if no user found with the id.
	  */
	 List<Sale> getSalesBySellerID(Integer sellerID, int offset, int limit);

	 /**
	  * Gets sale for the authenticated user
	  *
	  * @param session The HttpSession object
	  * @param offset the index (starting with 0) to start searching at
	  * @param limit the maximum result count to get
	  * @return the list of sales
	  * @throws UserNotAuthenticatedException if no authenticated user exists
	  * @throws UserDoesNotExistException if the user authenticated against the
	  * session does not exist. This case would be unusual.
	  */
	 List<Sale> getSalesByAuthenticatedUser(HttpSession session, int offset, int limit) throws UserNotAuthenticatedException;

	 /**
	  * Gets a list of sales created by a seller
	  *
	  * @param seller the user that owns the sales
	  * @return the list of sales
	  */
	 List<Sale> getSalesBySeller(User seller);

	 /**
	  * Gets the sale created by the seller whose ID is provided
	  *
	  * @param sellerID the ID of the seller
	  * @return the list of sales
	  * @throws UserDoesNotExistException if no seller with the matching ID
	  * exists
	  */
	 List<Sale> getSalesBySellerID(Integer sellerID) throws UserDoesNotExistException;

	 /**
	  * Gets sale for the authenticated user
	  *
	  * @param session The HttpSession object
	  * @return the list of sales
	  * @throws UserNotAuthenticatedException if no authenticated user exists
	  */
	 List<Sale> getSalesByAuthenticatedUser(HttpSession session) throws UserNotAuthenticatedException;

	 /**
	  * Gets the sale count by the seller
	  *
	  * @param seller the seller
	  * @return the sale count
	  */
	 int getSaleCountBySeller(User seller);

	 /**
	  * Gets sale count started by the seller whose ID matches sellerID
	  *
	  * @param seller the ID of the seller
	  * @return the sale count. If no user found with the seller id, returns 0
	  * 
	  */
	 int getSaleCountBySellerID(Integer sellerID);

	 /**
	  * Gets sale count for the authenticated user
	  *
	  * @param session The HttpSession object
	  * @return the sale count
	  * @throws UserNotAuthenticatedException if no authenticated user exists
	  * @throws UserDoesNotExistException if the user authenticated against the
	  * session does not exist. This case would be unusual.
	  */
	 int getSaleCountByAuthenticatedUser(HttpSession session) throws UserNotAuthenticatedException;
	 
	 /**
	  * Gets a sale by a sale ID
	  * @param saleID the sale ID
	  * @return the sale
	  * @throws SaleDoesNotExistException if no sale with the ID exists
	  */
	 Sale getSaleByID (Integer saleID) throws SaleDoesNotExistException;
	 
	  /**
	  * Gets a sale by a sale ID
	  * @param saleID the sale ID
	  * @return the sale.  if no sale exists by the ID, null is returned
	  */
	 Sale findSaleByID (Integer saleID);
	 
	 boolean getSaleFavouritedByUser (User user, Sale sale);
	 
	 void favouriteSaleForUser (User user, Sale sale) throws SaleAlreadyFavouritedByUserException;
	 
	 void unfavouriteSaleForUser (User user, Sale sale) throws SaleNotFavouritedByUserException;
	 
	 boolean getSaleFavouritedByUser (Integer userId, Integer saleID);
	 
	 List<Sale> getSalesFavouritedByUserID (Integer userID);
	 
	 List <Sale> getSalesFavouritedByUser (User user);
	 
	 List <Sale> getSalesFavouritedByAuthenticatedUser (HttpSession session) throws UserNotAuthenticatedException;
	 	 
	 List<Sale> getSalesFavouritedByUserID (Integer userID, int offset, int limit);
	 
	 List <Sale> getSalesFavouritedByUser (User user, int offset, int limit);
	 
	 List <Sale> getSalesFavouritedByAuthenticatedUser (HttpSession session, int offset, int limit) throws UserNotAuthenticatedException;
	 
	 int getFavouritedSaleCountByUser (User user);
	 
	 int getFavouritedSaleCountByUserID (Integer userID);	 
	 
	 int getFavouritedSaleCountByAuthenticatedUser (HttpSession session) throws UserNotAuthenticatedException;
	 
	 SaleLookupResult getSalesByQuery (SaleLookupQuery query) throws LocationNotFoundException;
	 
	 SaleLookupResult getSalesByQuery (SaleLookupQuery query, int offset, int limit) throws LocationNotFoundException;	 
}
